package realQuestion.didi.xuanzhanArr;

public class Class189 {
//TODO:2023/12/30   方法一
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        int[] newArr = new int[len];
        for (int i = 0; i < len; i++) {
            newArr[(i+k)%len]=nums[i];
        }
    }


    //TODO:2023/12/30  方法二
        public void rotate1(int[] nums, int k) {
            k %= nums.length;
            reverse(nums, 0, nums.length - 1);
            reverse(nums, 0, k - 1);
            reverse(nums, k, nums.length - 1);
        }

        public void reverse(int[] nums, int start, int end) {
            while (start < end) {
                int temp = nums[start];
                nums[start] = nums[end];
                nums[end] = temp;
                start += 1;
                end -= 1;
            }
        }



}
